<?php
/**
 * AdminLog 组件
 * 管理员操作日志
 * 
 * @author zzdboy
 * @version 1.0
 */
class AdminLogComponent extends Component {
	// 当前控制器
	private $curController = '';
	
	// 当前动作
	private $curAction = '';
	
	// 当前用户id
	private $admin_uid = '';
	
	// 当前用户姓名
	private $username = '';
	
	// 当前用户真实姓名
	private $AdminInfo = '';
	
	// 当前角色id
	private $roleid = '';
	
	/**
	 * Called before the Controller::beforeFilter().
	 *
	 * @access public
	 * @return void
	 */
	public function initialize(Controller $controller) {
		$this->curController = $controller->request->params ['controller'];
		$this->curAction = $controller->request->params ['action'];
		
		$this->admin_uid = $controller->Session->read ( 'admin_uid' );
		
		// 加载Admin model
		$controller->loadModel ( 'Admin' );
		$this->AdminInfo = $controller->Admin->GetAdminByID ( $this->admin_uid );
		
		$this->username = $controller->Session->read ( 'username' );
		$this->roleid = $controller->Session->read ( 'admin_roleid' );
	}
	
	/**
	 * 添加操作日志
	 *
	 * @access public
	 * @param string $remark
	 *        	日志信息(文本)
	 * @return bool
	 */
	public function addLog($remark = '') {
		$logsInstance = ClassRegistry::init ( 'AdminLogs' );
		
		$data ['AdminLogs'] ['uid'] = empty ( $this->AdminInfo ['Admin'] ['uid'] ) ? '0' : $this->AdminInfo ['Admin'] ['uid'];
		$data ['AdminLogs'] ['username'] = empty ( $this->AdminInfo ['Admin'] ['username'] ) ? '--' : $this->AdminInfo ['Admin'] ['username'];
		$data ['AdminLogs'] ['realname'] = empty ( $this->AdminInfo ['Admin'] ['realname'] ) ? '--' : $this->AdminInfo ['Admin'] ['realname'];
		$data ['AdminLogs'] ['remark'] = $remark;
		$data ['AdminLogs'] ['controller'] = $this->curController;
		$data ['AdminLogs'] ['action'] = $this->curAction;
		$logsInstance->add ( $data );
	}
}
?>